﻿#pragma once

#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QOpenGLBuffer>
#include <QOpenGLShaderProgram>
#include <QOpenGLVertexArrayObject>
#include <QMatrix4x4>
#include <QVector>

#include "AsGLCoordPainter.h"
#include "MyGLXYZPainter.h"
#include "NewPCIDemoDefine.h"
#include "CoreData.h"

class AsOpenGLWidget  : public QOpenGLWidget,protected QOpenGLFunctions
{
	Q_OBJECT

public:
	AsOpenGLWidget(QWidget *parent = nullptr);
	~AsOpenGLWidget();

	void setVertexArray(QVector<QVector3D> points);

signals:

public slots:
	void setXTranslate(float distance);
	void setYTranslate(float distance);
	void clearup();

protected:
	void initializeGL() override;
	void paintGL() override;
	void resizeGL(int w, int h) override;
	virtual void timerEvent(QTimerEvent *e) override;
	void mousePressEvent(QMouseEvent *e) override;
	void mouseMoveEvent(QMouseEvent *e) override;
	void mouseReleaseEvent(QMouseEvent *e) override;
	void wheelEvent(QWheelEvent *e) override;

private:
	void updateModel();
	void updateTransformParam();
	void setupVertexAttribs();
	void createLODModels();
	void createColorAndNormal(QVector<QVector3D> input);

	

private:

	QColor m_modelColor = QColor(144, 190, 244);
	int m_distance = 1;
	int m_xRot = 0;
	int m_tryRotX = 0;
	int m_yRot = 0;
	int m_tryRotY = 0;
	float m_xTrans = 0;
	float m_yTrans = 0;
	float m_zoomCoe = -4;
	MyGLTransParam m_transformParam;
	QOpenGLVertexArrayObject m_vao;
	QOpenGLBuffer m_vbo;
	QOpenGLShaderProgram *m_program;
	int m_projLoc;
	int m_mvLoc;
	int m_normalLoc;
	int m_plane;
	int m_lightPos;
	QMatrix4x4 m_projMat;
	QMatrix4x4 m_camera;
	QMatrix4x4 m_world;
	QVector<GLfloat> m_data;
	QVector<GLfloat> m_LODMData;
	QVector<GLfloat> m_LODSData;
	QPoint m_lastPos;
};
